10. 路由

1
cnpm install react-router-dom

src/App.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { Component } from 'react';
import Header from './common/header';
import store from './store';
import { Provider } from 'react-redux';
// 导入路由模块
import { BrowserRouter, Route } from 'react-router-dom';

class App extends Component {
render() {
return (
<Provider store={store}>
<div>
<Header />
<BrowserRouter>
<div>
{
//exact 代表严格匹配
}
<Route
path='/'
exact
render={()=><div>home</div>}>
</Route>
<Route
path='/detail'
exact
render={()=><div>detail</div>}>
</Route>
</div>
</BrowserRouter>
</div>
</Provider>
);
}
}
export default App;

代码地址